<template>
  <el-dialog
    v-loading="loading"
    :visible.sync="dialog"
    title="详情"
    width="500px"
    :close-on-click-modal="false"
    append-to-body
    @close="cancel"
  >
    <div>
      <el-form ref="apiForm" :model="param" :rules="rules" size="small" label-width="180px">
        <el-form-item label="作业类型：" prop="automationCode">
          <span>{{ param.automationCode }}</span>
        </el-form-item>
        <el-form-item label="执行作业：" prop="beanName">
          <el-select v-model="param.beanName" style="width: 280px">
            <el-option key="icmt" label="icmt" value="icmt" />
            <el-option key="cnmn" label="cnmn" value="cnmn" />
            <el-option key="ichg" label="ichg" value="ichg" />
          </el-select>
        </el-form-item>
        <el-form-item label="异常后处理：" prop="errorNext">
          <el-select v-model="param.errorNext" style="width: 280px">
            <el-option :key="1" label="继续后续操作" :value="1" />
            <el-option :key="2" label="中止后续操作" :value="2" />
          </el-select>
        </el-form-item>
      </el-form>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="text" @click="cancel">取消</el-button>
      <el-button type="primary" @click="doSubmit">确定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { Message } from 'element-ui'
import { saveStep } from '@/api/host'

export default {
  props: {
    parent: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      dialog: false,
      loading: false,
      param: {},
      rules: {
        beanName: [
          { required: true, message: '请选择执行作业', trigger: 'blur' }
        ],
        errorNext: [
          { required: true, message: '请选择异常后处理', trigger: 'blur' }
        ]
      }
    }
  },
  methods: {
    cancel() {
      this.dialog = false
      this.fileList = []
      this.param = {}
    },
    // 确定按钮触发
    doSubmit() {
      this.$refs.apiForm.validate((valid) => {
        if (valid) {
          this.loading = true
          saveStep(this.param).then(res => {
            this.parent.toQuery()
            Message({
              message: '操作成功。',
              type: 'success',
              duration: 3 * 1000
            })
            this.loading = false
            this.dialog = false
          }, error => {
            console.log(error)
            this.loading = false
          })
        }
      })
    }
  }
}
</script>
